package com.lineage.data.item_etcitem.add;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.datatables.sql.CharItemsTable;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ItemName;
import com.lineage.server.serverpackets.S_ItemStatus;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import java.util.Random;

public class ArmorEnchant extends ItemExecutor {
  private int _type;
  
  public static ItemExecutor get() {
    return new ArmorEnchant();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    int targObjId = data[0];
    L1ItemInstance tgItem = pc.getInventory().getItem(targObjId);
    if (tgItem == null)
      return; 
    if (tgItem.getItem().getType2() != 2)
      return; 
    L1ItemInstance enchant_item = pc.getInventory().getItem(tgItem.getId());
    int i = item.getItem().getItemId(), itemId = i;
    int j = enchant_item.getskilltype();
    int k = enchant_item.getskilltypelv();
    Random random = new Random();
    int chance = random.nextInt(100) + 1;
    int a1 = this._type;
    int a2 = this._type;
    int a3 = this._type;
    int a4 = this._type;
    int a5 = this._type;
    boolean is_enchanted = false;
    if (k == 5) {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("该装备已经Lv5了..已达上限"));
      return;
    } 
    switch (i) {
      case 92256:
        if (tgItem.getItem().getUseType() != 2) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fT此卷轴只能附加在盔甲"));
          return;
        } 
        if (a1 < chance) {
          is_enchanted = false;
          break;
        } 
        if (j == 113 || j == 114 || j == 115 || j == 116 || j == 117) {
          tgItem.setskilltypelv(k + 1);
          tgItem.setskilltype(j + 1);
          is_enchanted = true;
          break;
        } 
        if (j != 0)
          break; 
        tgItem.setskilltypelv(k + 1);
        tgItem.setskilltype(j + 113);
        is_enchanted = true;
        break;
      case 92257:
        if (tgItem.getItem().getUseType() != 20) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fT此卷轴只能附加在手套"));
          return;
        } 
        if (a2 < chance) {
          is_enchanted = false;
          break;
        } 
        if (j == 118 || j == 119 || j == 120 || j == 121 || j == 122) {
          tgItem.setskilltypelv(k + 1);
          tgItem.setskilltype(j + 1);
          is_enchanted = true;
          break;
        } 
        if (j != 0)
          break; 
        tgItem.setskilltypelv(k + 1);
        tgItem.setskilltype(j + 118);
        is_enchanted = true;
        break;
      case 92258:
        if (tgItem.getItem().getUseType() != 22) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fT此卷轴只能附加在头盔"));
          return;
        } 
        if (a3 < chance) {
          is_enchanted = false;
          break;
        } 
        if (j == 123 || j == 124 || j == 125 || j == 126 || j == 127) {
          tgItem.setskilltypelv(k + 1);
          tgItem.setskilltype(j + 1);
          is_enchanted = true;
          break;
        } 
        if (j != 0)
          break; 
        tgItem.setskilltypelv(k + 1);
        tgItem.setskilltype(j + 123);
        is_enchanted = true;
        break;
      case 92259:
        if (tgItem.getItem().getUseType() != 21) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fT此卷轴只能附加在长靴"));
          return;
        } 
        if (a4 < chance) {
          is_enchanted = false;
          break;
        } 
        if (j == 128 || j == 129 || j == 130 || j == 131 || j == 132) {
          tgItem.setskilltypelv(k + 1);
          tgItem.setskilltype(j + 1);
          is_enchanted = true;
          break;
        } 
        if (j != 0)
          break; 
        tgItem.setskilltypelv(k + 1);
        tgItem.setskilltype(j + 128);
        is_enchanted = true;
        break;
      case 92260:
        if (tgItem.getItem().getUseType() != 19) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fT此卷轴只能附加在斗篷"));
          return;
        } 
        if (a5 < chance) {
          is_enchanted = false;
          break;
        } 
        if (j == 133 || j == 134 || j == 135 || j == 136 || j == 137) {
          tgItem.setskilltypelv(k + 1);
          tgItem.setskilltype(j + 1);
          is_enchanted = true;
          break;
        } 
        if (j != 0)
          break; 
        tgItem.setskilltypelv(k + 1);
        tgItem.setskilltype(j + 133);
        is_enchanted = true;
        break;
    } 
    if (is_enchanted) {
      pc.getInventory().removeItem(item, 1L);
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fS产生强大光芒，防具天赋瞬间被神秘力量加强"));
      pc.sendPackets((ServerBasePacket)new S_ItemStatus(tgItem));
      pc.sendPackets((ServerBasePacket)new S_ItemName(tgItem));
      CharItemsTable cit = new CharItemsTable();
      try {
        pc.save();
        cit.updateskilltypelv(tgItem);
        cit.updateskilltype(tgItem);
      } catch (Exception e) {
        e.printStackTrace();
      } 
    } else {
      pc.getInventory().removeItem(item, 1L);
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fT强大光芒.但装备没任何影响.卷轴化为碎片"));
    } 
  }
  
  public void set_set(String[] set) {
    try {
      this._type = Integer.parseInt(set[1]);
    } catch (Exception exception) {}
  }
}
